package screens;

import media.AudioManager;
import media.Musics;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
import com.me.jnrgame.JnR;

public class PauseMenuWindow extends Window {

	JnR game;
	LevelScreen levelScreen;

	public PauseMenuWindow(String title, Skin skin, JnR _game,
			LevelScreen _levelScreen, boolean gameOver) {
		super(title, skin);
		game = _game;
		levelScreen = _levelScreen;
		this.setMovable(false);
		this.setSize(400, 200);
		this.setX(200);
		this.setY(140);
		game.setLevelScreen(levelScreen);

		TextButton resumeGameButton = new TextButton("Resume", skin);
		if (gameOver) {
			resumeGameButton.setDisabled(true);
			resumeGameButton.setColor(Color.LIGHT_GRAY);
		}
		resumeGameButton.addListener(new ChangeListener() {

			@Override
			public void changed(ChangeEvent event, Actor actor) {
				// TODO Auto-generated method stub

				closeWindow();
				AudioManager.resumeMusic();
				game.pauseGame(false);
			}

		});
		this.add(resumeGameButton).size(85f, 85f).uniform().spaceLeft(10);

		// register the button "options"
		TextButton restartButton = new TextButton("Restart", skin);
		restartButton.addListener(new ChangeListener() {

			@Override
			public void changed(ChangeEvent event, Actor actor) {
				LevelScreen levelScreen = new LevelScreen(2, game);
				AudioManager.playMusic(Musics.Level);
				game.pauseGame(false);
				closeWindow();
				game.setUpLevel(levelScreen);

			}
		});
		this.add(restartButton).size(85f, 85f).uniform().spaceLeft(10);

		// register the button "hall of fame"
		TextButton optionsButton = new TextButton("Options", skin);
		optionsButton.addListener(new ChangeListener() {

			@Override
			public void changed(ChangeEvent event, Actor actor) {
				// TODO Auto-generated method stub

				closeWindow();

				game.toOptionsScreen(1);

				Gdx.input.setInputProcessor(game.getOptionsScreen().getStage());
			}

		});
		this.add(optionsButton).size(85f, 85f).uniform().spaceLeft(10);

		// register the button "hall of fame"
		TextButton mainMenuButton = new TextButton("Menu", skin);
		mainMenuButton.addListener(new ChangeListener() {

			@Override
			public void changed(ChangeEvent event, Actor actor) {
				// TODO Auto-generated method stub
				closeWindow();
				game.toMainMenuScreen();
				Gdx.input
						.setInputProcessor(game.getMainMenuScreen().getStage());
				game.pauseGame(false);

			}

		});
		this.add(mainMenuButton).size(85f, 85f).uniform().spaceLeft(10)
				.spaceRight(10);
	}

	public PauseMenuWindow(String title, WindowStyle style) {
		super(title, style);
		// TODO Auto-generated constructor stub
	}

	public PauseMenuWindow(String title, Skin skin, String styleName) {
		super(title, skin, styleName);
		// TODO Auto-generated constructor stub
	}

	public void closeWindow() {

		this.remove();
	}

}
